<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单点登录测试</title>
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<h1>单点登录测试</h1>
<div id="userInfo">未登录</div>
<br>
<br>
<input type="button" name="退出登录" onclick="logout()" value="退出登录"/>
<script type="text/javascript">

    window.onload = function() {
        $.ajax({
            type: "GET",
            url: "/api/getUserInfo",
            dataType: "json",
            success: function(data){
                if (data.code == 8200){
                    $("#userInfo").text("用户:"+data.data);
                }else if (data.code == 8302){
                    alert("未登录,是否跳转到登录页?")
                    location.href = data.data+"?redirectUri="+location.href;
                }else {
                    alert(data.message)
                }
            }
        });
    }
    function logout() {
        $.ajax({
            type: "GET",
            url: "/api/logout",
            dataType: "json",
            success: function(data){
                if (data.code == 8200){
                    alert("退出成功,即将跳转登录页")
                    location.reload();
                }else {
                    alert(data.message)
                }
            }
        });
    }

</script>
</body>
</html>